package com.yue.jpa.constant;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能描述: TODO <br/>
 * 创建时间: 2016/12/22<br/>
 *
 * @author QiuYang
 */
public enum MapLogStatus {
    SUCCESS("成功", MapLogType.HIS),
    FAIL("失败", MapLogType.HIS),
    REPEAL("撤销", MapLogType.HIS),

    WAITING("排队", MapLogType.TMP),
    PLANNING("准备", MapLogType.TMP),
    READY("就绪", MapLogType.TMP),
    STORAGING("数据入库", MapLogType.TMP),
    STORAGED("已经入库", MapLogType.TMP),
    BUILDING("写入索引", MapLogType.TMP),
    COMPLETE("完成", MapLogType.TMP),
    ERROR("出错", MapLogType.TMP)
    ;

    private String desc;
    private MapLogType type;

    public String getDesc() {
        return desc;
    }

    public MapLogType getType() {
        return type;
    }

    MapLogStatus(String desc, MapLogType type){
        this.desc = desc;
        this.type = type;
    }

    private static final Map<MapLogStatus, String> infoDisplayTable = new LinkedHashMap<>();
    static{
        infoDisplayTable.put(WAITING, "none");
        infoDisplayTable.put(PLANNING, "mdb");
        infoDisplayTable.put(READY, "mdb");
        infoDisplayTable.put(STORAGING, "sqlite");
        infoDisplayTable.put(STORAGED, "sqlite");
        infoDisplayTable.put(BUILDING, "ocean");
        infoDisplayTable.put(COMPLETE, "ES");
    }

    public static Map<String, Boolean> getInfoDisplayByMapLogStatus(MapLogStatus status) {
        List<MapLogStatus> mapLogStatuses = new ArrayList<MapLogStatus>(infoDisplayTable.keySet());
        Map<String, Boolean> results = new LinkedHashMap<>();
        int pos = mapLogStatuses.indexOf(status);

        for (MapLogStatus s : mapLogStatuses){
            int p = mapLogStatuses.indexOf(s);
            if (p <= pos){
                results.put(infoDisplayTable.get(s), true);
                continue;
            }
            results.put(infoDisplayTable.get(s), false);
        }

        return results;
    }

    public static MapLogStatus getMapLogStatusByDesc(String desc) {
        MapLogStatus[] status = MapLogStatus.values();
        for (MapLogStatus s : status){
            if (s.getDesc().equals(desc)){
                return s;
            }
        }
        return null;
    }

    public static Object getMapLog(String status) {
        if (status == null) {
            return null;
        }
        try {
            return Enum.valueOf(MapLogStatus.class, status);
        } catch (IllegalArgumentException e) {
            return null;
        }
    }

//    public static void main(String[] args) {
//        Map<String, Boolean> d = getInfoDisplayByMapLogStatus(STORAGED);
//        System.out.println(d);
//    }

}
